﻿
using System.Collections;

/// <summary>
/// IO消息
/// </summary>
public class IOMessage {
    /// <summary>
    /// 消息码
    /// </summary>
    int _code;
    /// <summary>
    /// 消息状态
    /// </summary>
    int _state;
    /// <summary>
    /// 消息数据
    /// </summary>
    HashtableEx _args;

    public int code { get { return _code; } }
    public int state { get { return _state; } }
    public HashtableEx args { get { return _args; } }

    public IOMessage(int code,int state = IOStates.STATE_OK, HashtableEx args = null)
    {
        _code = code; _state = state; _args = args;
    }

    public static IOMessage ForCode(int code)
    {
        return new IOMessage(code, 0, new HashtableEx(new Hashtable()));
    }

    public string ToJSON()
    {
        Hashtable data = new Hashtable();
        data["code"] = _code;
        data["state"] = _state;
        if (_args != null)
        {
            data["args"] = _args.GetData();
        }
        return MiniJSON.JsonEncode(data);
    }
}
